@echo off
rem K8s Deployment Resource Extractor - Windows Batch Launch Script

rem Switch to script directory
cd /d "%~dp0"

rem Check Python environment
where python >nul 2>&1
if %ERRORLEVEL% neq 0 (
    echo Error: Python command not found. Please ensure Python is installed and added to PATH
    exit /b 1
)

rem Initialize variables
set INTERACTIVE=0
set CONFIG_FILE=config.yaml
set SOURCE_DIR=sources
set OUTPUT_DIR=outputs
set VERBOSE=0
set FORCE_RUN=0

rem Parse command line arguments
:parse_args
if "%~1"=="" goto :done_parsing
if /i "%~1"=="-i" set INTERACTIVE=1
if /i "%~1"=="--interactive" set INTERACTIVE=1
if /i "%~1"=="-c" set CONFIG_FILE=%2 & shift
if /i "%~1"=="--config" set CONFIG_FILE=%2 & shift
if /i "%~1"=="-s" set SOURCE_DIR=%2 & shift
if /i "%~1"=="--source" set SOURCE_DIR=%2 & shift
if /i "%~1"=="-o" set OUTPUT_DIR=%2 & shift
if /i "%~1"=="--output" set OUTPUT_DIR=%2 & shift
if /i "%~1"=="-v" set VERBOSE=1
if /i "%~1"=="--verbose" set VERBOSE=1
if /i "%~1"=="-y" set FORCE_RUN=1
if /i "%~1"=="--yes" set FORCE_RUN=1
shift
goto :parse_args
:done_parsing

rem Interactive mode
if %INTERACTIVE%==1 (
    if %FORCE_RUN%==0 (
        echo Welcome to K8s Deployment Resource Extractor
        echo ===========================================
        
        rem Source directory
        set /p SOURCE_INPUT="Source directory [%SOURCE_DIR%]: "
        if not "%SOURCE_INPUT%"=="" set SOURCE_DIR=%SOURCE_INPUT%
        
        rem Output directory
        set /p OUTPUT_INPUT="Output directory [%OUTPUT_DIR%]: "
        if not "%OUTPUT_INPUT%"=="" set OUTPUT_DIR=%OUTPUT_INPUT%
        
        rem Config file
        set /p CONFIG_INPUT="Configuration file [%CONFIG_FILE%]: "
        if not "%CONFIG_INPUT%"=="" set CONFIG_FILE=%CONFIG_INPUT%
        
        rem Verbose mode
        set /p VERBOSE_INPUT="Enable verbose logging? (y/N): "
        if /i "%VERBOSE_INPUT%"=="y" set VERBOSE=1
        
        rem Show summary
        echo.
        echo Settings Summary:
        echo   Source Directory: %SOURCE_DIR%
        echo   Output Directory: %OUTPUT_DIR%
        echo   Configuration: %CONFIG_FILE%
        echo   Verbose: %VERBOSE%
        if %VERBOSE%==1 (
            echo   Verbose: Yes
        ) else (
            echo   Verbose: No
        )
        
        rem Final confirmation
        set /p CONFIRM="Start extraction with these settings? (Y/n): "
        if /i "%CONFIRM%"=="n" (
            echo Extraction cancelled by user
            exit /b 0
        )
    )
)

rem Build command arguments
set ARGS=--source "%SOURCE_DIR%" --output "%OUTPUT_DIR%" --config "%CONFIG_FILE%"
if %VERBOSE%==1 set ARGS=%ARGS% --verbose

rem Start the application
echo Starting K8s Deployment Resource Extractor...
python -m src %ARGS%

rem Check exit status
if %ERRORLEVEL% neq 0 (
    echo Application exited with error code: %ERRORLEVEL%
    exit /b %ERRORLEVEL%
)

exit /b 0
